package com.digitalcollege.bean.custom;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

/**
 * @class: PageResult
 * @author: liyusheng
 * @description:
 * @date: 2022/12/17 20:40
 */
@ApiModel("分页结果")
@Data
@AllArgsConstructor
@NoArgsConstructor
public class PageResult<T> {
    @ApiModelProperty("总数")
    private Long total;

    @ApiModelProperty("记录")
    private List<T> records;

    public static <E> PageResult<E> buildResult(Long total, List<E> records) {
        return new PageResult<>(total, records);
    }

    public static <E> PageResult<E> buildResult(IPage<E> page) {
        return new PageResult<>(page.getTotal(), page.getRecords());
    }

}
